﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Syndication;

namespace ajayumi.develop.win32.GRssReader.Service.Model
{
    public class ArticleInfo : SyndicationItem
    {
        public List<string> CategoryList { get; set; }
        public List<State> StateList { get; set; }
        public string TitleText { get; private set; }
        public string SummayText { get; set; }
        public string ContentText { get; set; }
        public FeedBriefInfo FeedInfo { get; private set; }
        public IEnumerable<ArticleImageInfo> ArticleImageInfos { get; set; }

        public ArticleInfo() { }
        
        public ArticleInfo(SyndicationItem item)
            : base(item)
        {
            this.TitleText = Utility.GetTextSyndicationContent(this.Title);
            this.SummayText = Utility.GetTextSyndicationContent(this.Summary);
            this.ContentText = Utility.GetTextSyndicationContent(this.Content);
            if (string.IsNullOrEmpty(this.SummayText))
            { this.SummayText = this.ContentText; }

            this.ArticleImageInfos = Utility.GetImageResourceList(this.SummayText);

            this.CategoryList = new List<string>();
            this.StateList = new List<State>();

            // Get labels/categories.
            foreach (var cat in item.Categories)
            {
                State state = StateFormatter.ToState(cat.Label);
                if (state != State.Label && state != State.Unknown)
                { this.StateList.Add(state); }

                if (cat.Name.EndsWith(string.Concat("/label/", cat.Label)))
                {
                    this.CategoryList.Add(cat.Label);
                }
            }

            this.FeedInfo = new FeedBriefInfo(item.SourceFeed);
        }



    }
}
